<?php

# Import needed files
require("config.php");
require("functions.php");
require("arrays.php");
require("headers.php");
require("body.php");


# Connect to database


# Get Basic Input from post
foreach ($SERVER["POST"] as $key => $value) {
	$post[$key] = $value;
}

# Check to see if $action from post is 1 (first time pass through)
if ($post["action"] == "1") {
	# Set character variables from basic info in post
	foreach ($post as $key => $value) {
		$character[$key] = $value;
	};
	# Create a row in the database for the character data
	$row = create_character($character);
	#Create Form to submit data to page for next pass through
	mk_form();
	# Post the Row number along to the next pass through
	mk_post("row", $row);
	# Echo a short message to tell the user to click to move on
	mk_echo("Press to continue...");
	# Make a submit button that will set Action in Post to 2
	mk_submit(2);

};

if ($post["action"] == "2") {

# Retrieve character data from database
$character = get_info($sql, "characters", $post["row"]);

# Get Race/Class Data from database
$races = get_info($sql, "races", 0);
$classes = get_info($sql, "classes", 0);

# Make a Form to submit data back to this page with
mk_form();

# Create 2 tables for Races and Classes with Radio Buttons for each Displaying first 3 columns (ID, Name, Short Description)
mk_table($config_table, $races, 3, "radio");
mk_table($config_table, $classes, 3, "radio");
# Post the Row number along to the next pass through
mk_post("row", $row);
# Make a submit button that will set Action in Post to 3
mk_submit(3);

}

if ($post["action"] == "3") {
	mk_form();
	mk_post("row", $row);

	# Retrieve character data from database
	$character = get_info($sql, "characters", $post["row"]);
	# Get info about characters first class selection (Id Number)
	$temp = get_info($sql, "classes", $character["classes"][0]["id"]);
	# Check prerequisets of character verses class info (1 signifies class check)(other kinds will be added on later)
	$results = chk_prereq($character, $temp, 1);
	if ($results == 1) {
		mk_echo("Press submit to continue...");
		mk_submit(4);
	} else {
		#############################################
		## FIGURE OUT WAY TO BACKUP TO PICK A DIFFERENT CLASS 
		## (Maybe something with changing the class selections ID $character["classes"][0]["id]
		################################################
	};
};


require("footer.php");
?>
